package com.hp.attendance.serlvet.oneself;



import com.hp.attendance.entity.Employee;
import com.hp.attendance.service.OneselfService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//个人信息修改
@WebServlet("/oneselfUpdate")
public class OneselfUpdateServlet extends HttpServlet {
    private OneselfService oneselfService = new OneselfService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            int id = Integer.parseInt(req.getParameter("id"));
            int employeeNumber = Integer.parseInt(req.getParameter("employeeNumber"));
            String name = req.getParameter("name");
            String password = req.getParameter("password");
            String gender = req.getParameter("gender");
            Date date = new SimpleDateFormat("yyyy-MM-dd").parse(req.getParameter("date"));
            String telephone = req.getParameter("telephone");
            String email = req.getParameter("email");
            String address = req.getParameter("address");
            String education = req.getParameter("education");
            String notes = req.getParameter("notes");
            Employee employee = new Employee(id, employeeNumber, name, gender, date, telephone, email, address, null,education,null,null,date,password, notes);
            oneselfService.UpdateOneself(employee);
            req.getRequestDispatcher("/oneselfDetail").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
